package com.supereye.platform.web.sys.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.supereye.platform.util.EncodeUtil;
import com.supereye.platform.web.sys.dao.SysUserDao;
import com.supereye.platform.web.sys.model.SysUser;

@Service
public class LoginService {
	@Resource
	private SysUserDao sysUserDao;
	
	public SysUser login(String username, String password) throws Exception {
		
		SysUser param = new SysUser();
		param.setAccount(username);
		
		List<SysUser> list = sysUserDao.getUserList(param);
		
		if(list.size() < 1){
			throw new Exception("账号不存在");
		}
		
		SysUser user = list.get(0);
		
		String encodePassword = EncodeUtil.toMd5(password);
		if(!encodePassword.equals(user.getPassword())){
			throw new Exception("密码不正确");
		}
		
		return user;
	}

}
